import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
// import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lcapp/basic/local_info.dart';
import 'package:lcapp/page/splash/splash.dart';
import 'package:lcapp/routes/route.dart';
import 'model/Observer/asr_navigator_observer.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
    [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown],
  );
  AsrLocalInfo.init().then((value){
    runApp(MyApp());
  });
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(
         750,
        1334,
      ),
      builder: (_, child) => MaterialApp(
        title: '粮策',
        theme: buildThemeData(),
        locale: const Locale('zh', 'CN'),
        localizationsDelegates: const [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('zh', 'CN'),
          Locale('en', 'US'),
        ],
        home: SplashPage(),
        onGenerateRoute: ASRRoute().onGenerateRoute,
        navigatorKey: ASRRoute.navigatorKey,
        builder: (context, widget) {
          return FlutterEasyLoading(
            child: MediaQuery(
              //设置文字大小不随系统设置改变
              data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
              child: FlutterSmartDialog(
                child: widget,
              ),
            ),
          );
        },
        navigatorObservers: [
          MyNavigatorObserver(),
        ],
      ),

    );
  }
}

ThemeData buildThemeData() {
  const Color primaryColor = Colors.white;
  return ThemeData(
    primaryColor: primaryColor,
    appBarTheme: AppBarTheme(
      iconTheme: IconThemeData(color: Colors.black),
      backgroundColor: Colors.white,
    ),
    textSelectionTheme: TextSelectionThemeData(
      cursorColor: Color(0xFFFF3000),
    ),
    buttonTheme: ButtonThemeData(),
  );
}


